from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('demo_309_布局管理器')
        self.resize(500, 500)
        self.setup_ui()
        #QMetaObject.connectSlotsByName(self)

    def setup_ui(self):
        self.布局管理()

    def 布局管理(self):
        label1 = QLabel('标签1')
        label1.setObjectName('label1')

        label2 = QLabel('标签2')
        label2.setObjectName('label2')

        label3 = QLabel('标签3')
        label3.setObjectName('label3')

        label5 = QLabel('标签5')
        label5.setObjectName('label5')

        label6 = QLabel('标签6')
        label6.setObjectName('label6')

        label7 = QLabel('标签7')
        label7.setObjectName('label7')

        self.setStyleSheet("""
                   QLabel#label1{
                      background-color: cyan;
                  }
                  QLabel#label2{
                      background-color: yellow;
                  }
                  QLabel#label3{
                      background-color: red;
                  }
                  QLabel#label5{
                      background-color: pink;
                  }
                  QLabel#label6{
                      background-color: blue;
                  }
                  QLabel#label7{
                      background-color: cyan;
                  }
              """)

        h_layout = QHBoxLayout()
        h_layout.addWidget(label5)
        h_layout.addWidget(label6)
        h_layout.addWidget(label7)

        # v_layout = QHBoxLayout()
        v_layout = QVBoxLayout()
        v_layout.addWidget(label1)

        v_layout.addWidget(label2)
        v_layout.addLayout(h_layout)

        v_layout.addWidget(label3)
        #v_layout.setContentsMargins(20, 40, 60, 80)
        #v_layout.setSpacing(20)


        v_layout.setDirection(QBoxLayout.TopToBottom)
        #v_layout.setDirection(QBoxLayout.BottomToTop)

        #会设置父子关系
        self.setLayout(v_layout)
        #self.setLayoutDirection(Qt.LeftToRight)
        #self.setLayoutDirection(Qt.RightToLeft)
        #self.setLayoutDirection()
        print(self.children())


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)

    win = Window()
    win.show()
    
    sys.exit(app.exec_())
